home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 2.9 KB | 119 lines | [TEXT/R*ch] |
- /*
- File: StringInfo.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __DEBUGASSERT__
- #include "DebugAssert.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- #ifndef __STRINGINFO__
- #include "StringInfo.h"
- #endif
-
- /***********************************|****************************************/
-
- TStringInfo::TStringInfo ( const char * str )
- {
- SetString ( (const void *) str, strlen ( str ) );
- }
-
- /***********************************|****************************************/
-
- TStringInfo::TStringInfo ( const Str255 str )
- {
- SetString ( (const void *) &str[1], str [ 0 ] );
- }
-
- /***********************************|****************************************/
-
- TStringInfo::TStringInfo ( const RString& rStr )
- {
- SetString ( (const void *) rStr.body, rStr.dataLength );
- }
-
- /***********************************|****************************************/
-
- TStringInfo::TStringInfo ( const void * data, unsigned long length )
- {
- SetString ( data, length );
- }
-
- /***********************************|****************************************/
-
- TStringInfo::~TStringInfo ()
- {
- }
-
- /***********************************|****************************************/
-
- short TStringInfo::Count ( char c ) const
- {
- return fCount [ (unsigned short) c ];
- }
-
- /***********************************|****************************************/
-
- short TStringInfo::First ( char c ) const
- {
- return fFirst [ (unsigned short) c ];
- }
-
- /***********************************|****************************************/
-
- short TStringInfo::Last ( char c ) const
- {
- return fLast [ (unsigned short) c ];
- }
-
- /***********************************|****************************************/
-
- void TStringInfo::SetString ( const char * str )
- {
- SetString ( (const void *) str, strlen ( str ) );
- }
-
- /***********************************|****************************************/
-
- void TStringInfo::SetString ( const Str255 str )
- {
- SetString ( (const void *) &str[1], str [ 0 ] );
- }
-
- /***********************************|****************************************/
-
- void TStringInfo::SetString ( const RString& rStr )
- {
- SetString ( (const void *) rStr.body, rStr.dataLength );
- }
-
- /***********************************|****************************************/
-
- void TStringInfo::SetString ( const void * data, unsigned long length )
- {
- // Set the first, count, and last arrays to 0
- for (register unsigned short i = 0; i < 256; ++i)
- fFirst[ i ] = fLast [ i ] = fCount [ i ] = 0;
-
- for ( i = 0; i < length; ++i ) {
- fFirst [ (unsigned short) ( ((char *) data) [ length - i ] ) ] = length - i;
- char c = ((char *) data ) [ i ];
- fCount [ (unsigned short ) c ] ++;
- fLast [ ( unsigned short) c ] = i;
- }
- }
-
- /***********************************|****************************************/
-